module.exports = (quanxian) => {
  return async function (ctx, next) {
    try {
      const url = ctx.request.header.url;
      const token = ctx.request.header.access_token;
      const { rolename_name } = await ctx.app.jwt.verify(token, ctx.app.config.jwt.secret);
      let menu = await ctx.app.model.Menutotal.findAll({ where: { rolename_name, menuson_address: url } });
      // console.log(url,rolename_name,quanxian);
      // console.log(menu);
      if (menu == '' || menu == null || menu == undefined) {
        ctx.body = {
          code: 40003,
          msg: '权限不足',
        };
        return;
      }
      if (menu[0].dataValues[quanxian] == 1) {
        await next();
      } else {
        ctx.body = {
          code: 40002,
          msg: '权限不足',
        };
      }
    } catch (err) {
      ctx.body = {
        code: 50001,
        msg: err.message,
      };
    }
  };
};
